// 接口域名
// #ifdef H5
const BASE_URL = ''
// #endif
// #ifndef H5
const BASE_URL = 'https://ju.yibenwanli.cn'
// #endif
const request = (config) => {
	if(!config.showlod){
		uni.showLoading({
			title:''
		})
	}
	
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + config.url,
			method: config.method || 'GET',
			
			data: config.data || {},
			header: { // "Bearer " +  Authorization
				"Authorization":"Bearer "+(uni.getStorageSync('schooltoken') || ""),
				"provinceId":uni.getStorageSync('schoolarea').provinceId||"",
				"cityId":uni.getStorageSync('schoolarea').cityId||"",
			},
			success: (res) => {
				// console.log(res.data.code )
				uni.hideLoading()
				if (res.data.code == 400) {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/index/login'
						})
					}, 2000)
				}
				if (res.data.code == 0) {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
				}
				if (res.data.code == 302) {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/index/bindphone'
						})
					}, 2000)
				}
				resolve(res)
			},
			fail: (err) => {
				// uni.hideLoading()
				reject(err)
				console.log(err)
			}
		})
	})
};
// 上传

export {
	request,
	BASE_URL
};
